# Created by Gao Song on 2019-04-17

import lqu
import pandas as pd


def pct_to_pos(mv, pct, price):
    res = pd.Series()

    for sym in pct.keys():
        mul = lqu.get_contract_multiplier(sym)
        hands = round(mv * pct[sym] / price[sym] / mul)
        if hands == 0:
            continue
        res[sym] = hands
    return res

def future_pos_limit(pos):
    # TODO no use

    return pos

def min_hands_limit(pos):
    return pos

def pct_to_pos_stock(mv, pct, price):
    res = pd.Series()

    for sym in pct.keys():
        if pct[sym] == 0:
            res[sym] = 0
        else:
            if sym.startswith('68'):
                hands = round(mv * pct[sym] / price[sym] / 200) * 200
            else:
                hands = round(mv * pct[sym] / price[sym] / 100) * 100
            res[sym] = hands
    return res